<template name="sendcar">
	<!-- 物资巡检，作废，使用反馈，状态查询 列表 -->
	<view class="mypage">

		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入申请人" v-model="keyword"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in orderList"
				:key="index">

				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold"> 单号 ：{{ item.BILLNO || item.PK_AUSCRAP }}</text>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view>
						<view class="cu-tag line-brown sm">
							{{ index+1}}
						</view>
					</view>
				</view>

				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">设备：</text>
					<text>{{ item.EQUIPNAME || '' }}</text>
				</view>

				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">物资：</text>
					<text>{{ item.MATERIALNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">规格：</text>
					<text>{{ item.MATSPEC || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text class="card-label text-black">数量：</text>
					<text> {{ item.NUM || item.NNUM }}</text>
				</view>

				<view class="" v-if="busType==1">
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">巡检人：</text>
						<text>{{ item.INSPCEER || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">巡检说明：</text>
						<text>{{ item.VMEMO || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-gray"></text>
						<text class="card-label text-black">巡检时间：</text>
						<text>{{ item.INSPCETIME || '' }}</text>
					</view>
				</view>

				<view class="" v-if="busType==2">
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">使用人：</text>
						<text>{{ item.USEMAN || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">反馈内容：</text>
						<text>{{ item.VMEMO || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-gray"></text>
						<text class="card-label text-black">反馈时间：</text>
						<text>{{ item.BACKTIME || '' }}</text>
					</view>
				</view>

				<view class="" v-if="busType==3">
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">使用人：</text>
						<text>{{ item.USEMAN || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">物资状态：</text>
						<text>{{ item.MATSTATE || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">状态说明：</text>
						<text>{{ item.VMEMO || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-gray"></text>
						<text class="card-label text-black">登记时间：</text>
						<text>{{ item.REGTIME || '' }}</text>
					</view>
				</view>

				<view class="" v-if="busType==4">
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">申请人：</text>
						<text>{{ item.APPLYER || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-blue"></text>
						<text class="card-label text-black">报废原因：</text>
						<text>{{ item.VMEMO || '' }}</text>
					</view>
					<view class="card-list-row-1">
						<text class="cuIcon-title text-gray"></text>
						<text class="card-label text-black">报废时间：</text>
						<text>{{ item.SCRAPTIME || '' }}</text>
					</view>
				</view>


			</view>
		</view>
		
		<view class="next-btn-wrap " @click="nextTap">
			<button class="big-add bg-green shadow-blur">
				<text class="cuIcon-add text-bold"></text>
			</button>
		</view>
		
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js'
	import utils from '@/common/util.js'
	let _self, page = 1,
		total = 1,
		pageTitle, busType, requeryURL;
	let URLTYPE = {
		1: '/api/APPCommon/GetListPage_AU_MATINSPEC',
		2: '/api/APPCommon/GetListPage_AU_USEBACK',
		3: '/api/APPCommon/GetListPage_AU_MATTRACK',
		// 4:'/api/APPCommon/GetListPage_Break_APP'
		4: '/api/APPCommon/GetEquipmentScrap'
	}
	let query = {
		"category": "BILLNO",
		"page": 1,
		"rows": 10,
		"sidx": "CREATIONTIME",
		"sord": "desc",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let bsTypeKey = {
		ware: 1,
		org: 3,
		company: 2
	}
	let queryJson = {};
	// {BTCATEGORY:1,MOVETYPE:0},
	export default {
		computed: mapState(['userInfo']),
		data() {
			return {
				orderList: [],
				keyword: '',
				busType: 1
			};
		},
		onLoad(params) {
			_self = this
			console.log(params);
			page = 1;
			total = 1;
			busType = params.type
			this.busType = params.type
			pageTitle = params.title
			this.keyword = ''
			queryJson = {}
			getApp().globalData.queryJsonLS = null 
			query.account = this.userInfo.Account
			query.userId = this.userInfo.UserId

			let getULR = URLTYPE[params.type];
			requeryURL = this.userInfo.BaseURL + getULR;
			
			if(params.type == 4){
				query.sidx = 'SCRAPTIME'
			}else{
				query.sidx = 'CREATIONTIME'
			}
			
			this.getNewsList();
		},
		// 导航栏点击
		onNavigationBarButtonTap(e) {
			// e.index == 1 ? uni.navigateTo({
			// 	url: 'onsite?type=' + busType
			// }) : this.openScanMater();
			
			if(e.index==0){
				this.listenOnce()
				uni.navigateTo({
					url: '/pages/public/query?type=menu1017' 
				})
			}else{
				_self.openScanMater();
			}
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			this.orderList = [];
			this.getNewsList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},
		// 加载更多
		onReachBottom: function() {
			this.getNewsList();
		},
		methods: {
			
			nextTap(){
				uni.navigateTo({
					url: 'onsite?type=' + busType
				})
			},
			
			// 初始监听
			listenOnce() {
				uni.$off('reload')
				uni.$once("reload", function(data) {
					queryJson= { ...queryJson , ...data }
					getApp().globalData.queryJsonLS = queryJson
					_self.handelSearch()
				});
			},
			
			handelSearch() {
				queryJson.APPLYER = _self.keyword;
				queryJson.keyword = _self.keyword;
				page = 1;
				total = 1;
				this.orderList = [];
				this.getNewsList();
			},
			// 扫描设备
			openScanMater() {
				this.$utils.openScanUtils(0, 0, (res) => {
					if (res.includes('TYPE:8')) {
						let arr = res.split('|');
						let AddItem = {
							PK_EQUIP: '',
							EQUIPNAME: '',
							IMPUNUM: ''
						}
						queryJson.EQUIPNAME = arr[1]
						page = 1;
						total = 1;
						_self.orderList = [];
						_self.getNewsList();
					} else {
						this.$utils.tips('非设备二维码,无法使用')
					}
				})
			},
			getNewsList() {
				if (page > total) {
					return uni.showToast({
						icon: 'none',
						title: '没有数据了。'
					})
				}
				query.page = page;
				query.queryJson = JSON.stringify(queryJson);
				// console.log(query);
				// console.log(requeryURL);
				this.axios({
					url: requeryURL,
					data: query,
					isLoading: 1
				}).then(res => {
					let {
						IsSuccess,
						Result,
						Message
					} = res;
					// console.log(res);
					_self.setPageTitle(pageTitle + '列表(' + Result.records + ')')
					_self.orderList = [..._self.orderList, ...Result.rows]
					total = Result.total
					page++
				})
			},

			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},

			openDetail(e) {
				// console.log(e);
				let Path = '/pages/tab04/new_shift/over_out?id=' + _self.orderList[e].BILLNO + '&busType=' + busType +
					'&typeKey=' + queryJson.BTYPE + '&data=' + encodeURIComponent(JSON.stringify(_self.orderList[e]));
				// console.log(Path);
				uni.navigateTo({
					url: Path
				})
			},

			openScan(id, index) {
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						// console.log(res)
						if (res.scanType != 'QR_CODE') {
							return uni.showToast({
								icon: 'none',
								title: '类型错误，请重新扫描'
							})
						}
						let t = res.result;
						_self.keyword = t;
						_self.handelSearch()
					}
				});

			}

		}
	}
</script>

<style scoped lang="scss">
	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.card-label {
		display: inline-block;
		width: 150upx;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}
	
	.next-btn-wrap{
		.big-a{
			font-size: 20rpx;
			border-radius: 100%;
		}
	}
</style>